package com.edu.service.imlp;

import com.edu.dao.VehiclesDao;
import com.edu.dao.impl.VehiclesDaoImpl;
import com.edu.entity.PageBean;
import com.edu.entity.Vehicles;
import com.edu.service.VehiclesService;

import java.util.List;

public class VehiclesServiceImpl implements VehiclesService {
    VehiclesDao vehiclesDao = new VehiclesDaoImpl();

    @Override
    public PageBean<Vehicles> queryByType(String type, int page, int pageSize) {
        PageBean<Vehicles> pageBean = new PageBean<>();

        int count = vehiclesDao.queryByTypeCount(type);//总条数

        int PageCount = count % pageSize == 0 ? count % pageSize : count / pageSize + 1;//总页数

        //判断越界
        page = page < 1 ? 1 : page;
        page = page > PageCount ? PageCount : page;
        List<Vehicles> list = vehiclesDao.queryByType(type, page , pageSize);

        pageBean.setConut(count);
        pageBean.setCurrentPage(page);
        pageBean.setPageCount(PageCount);
        pageBean.setPageSize(pageSize);
        pageBean.setData(list);
        return pageBean;
    }

    @Override
    public Vehicles queryById(int id) {
        return vehiclesDao.queryByTId(id);
    }
}
